//
//  BankCardListVC.m
//  JinFuThree
//
//  Created by 毛韶谦 on 2018/9/10.
//  Copyright © 2018年 毛韶谦. All rights reserved.
//

#import "BankCardListVC.h"
#import "BankCardListCell.h"
#import "MyRequestTools.h"

@interface BankCardListVC ()<UITableViewDataSource, UITableViewDelegate>

@property (nonatomic, strong) UITableView *mainTableView;
@property (nonatomic, strong) NSMutableArray *cardListArr;

@end

@implementation BankCardListVC

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initUI];
    // Do any additional setup after loading the view.
}

- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    
    [self updateListData];
}

- (void)initUI {
    
    self.title = @"支持银行卡";
    self.mainTableView.backgroundColor = [UIColor whiteColor];
}


- (void)updateListData {
    
    [MyRequestTools getSupportBankListDataSuccess:^(id  _Nullable responseObject) {
        
        if ([[NSString stringWithFormat:@"%@",[responseObject objectForKey:@"code"]] isEqualToString:@"200"]) {
            self.cardListArr = [responseObject objectForKey:@"data"];
            [self.mainTableView reloadData];
        }
        
    } Failure:^(id  _Nullable responseObject, NSError * _Nullable error) {
        
    }];
    
}



#pragma mark tableView代理方法

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    
    return self.cardListArr.count + 1;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 35;
}
- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section {
    
    return 30.01f;
}
- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section {
    
    return 30.01f;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    BankCardListCell *cell = [tableView dequeueReusableCellWithIdentifier:@"BankCardListCell"];
    if (!cell) {
        cell = [[BankCardListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"BankCardListCell"];
    }
    [cell updateInfoCellWithModel:indexPath];
    if (indexPath.row != 0) {
        NSDictionary *dic = self.cardListArr[indexPath.row-1];
        cell.leftLabel.text = [dic objectForKey:@"bankName"];
        cell.rightLabel.text = [NSString stringWithFormat:@"%@",[dic objectForKey:@"limit"]];
    }
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section {
    
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor whiteColor];
    return view;
}
- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section {
    
    UIView *view = [[UIView alloc] init];
    view.backgroundColor = [UIColor whiteColor];
    return view;
}


- (UITableView *)mainTableView {
    
    if (!_mainTableView) {
        _mainTableView = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, ScreenWidthMao, ScreenHeight - SafeAreaTopHeight) style:UITableViewStyleGrouped];
        _mainTableView.separatorStyle = UITableViewCellSeparatorStyleNone;
        _mainTableView.delegate = self;
        _mainTableView.dataSource = self;
        
        [self.view addSubview:_mainTableView];
    }
    return _mainTableView;
}

- (NSMutableArray *)cardListArr {
    
    if (!_cardListArr) {
        _cardListArr = [NSMutableArray array];
    }
    return _cardListArr;
}


- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
